package model

import (
	"fmt"
	"github.com/jinzhu/gorm"
	"hepan1/src/util"
	"math/rand"
	"strconv"
	"time"
)

//// Exec 执行插入语句
//func Exec(stm string) error {
//	_,err := Db.Exec(stm)
//	return err
//}
//
//// Exec2 执行语句，返回受形象的行数
//func Exec2(stm string)(int,error){
//	res,err := Db.Exec(stm)
//	if util.Check(err){
//		return 0,err
//	}
//	s,_ :=res.RowsAffected()
//	return int(s),nil
//}
//
//// QueryRow 判断查询语句是否有返回值
//func QueryRow(stm string) error {
//	var m string
//	valid := Db.QueryRow(stm).Scan(&m)
//	return valid
//}

//// GetTheUser 获得所有的用户,返回一个用户的切片
//func GetTheUser() ([][]string,error){
//	stm := "SELECT * from drawusers"
//	rows ,err := Db.Query(stm)
//	if err!=nil{
//		return nil,err
//	}
//
//	var users [][]string
//	var ID,openid,chou,sui1,sui2,sui3,sui4,sui5,sui6,sui7,sui8,sui9,nick,pic,ct,ut string
//	for rows.Next(){
//		var user []string
//		rows.Scan(&ID,&openid,&chou,&sui1,&sui2,&sui3,&sui4,&sui5,&sui6,&sui7,&sui8,&sui9,&nick,&pic,&ct,&ut)
//		user = append(user,ID,openid,chou,sui1,sui2,sui3,sui4,sui5,sui6,sui7,sui8,sui9,nick,pic,ct,ut)
//		users = append(users,user)
//	}
//	fmt.Println(users)
//	return users,nil
//}

// Howmuchchou 返回抽奖次数
func Howmuchchou(uid string)(int,string){
	//sql := fmt.Sprintf("SELECT chou from drawusers where openid = '%s'", uid)
	var user Drawusers
	if Db.Where("openid = ?",uid).First(&user).RowsAffected ==0{
		return 0,"没有这个人"
	}
	fmt.Println(user)
	//rows := DB.QueryRow(sql)
	//var times int
	//err := rows.Scan(&times)
	//if err!=nil{
	//	return 0, err
	//}
	//return times, nil
	return user.Chou, ""
}

//// 每次抽碎片调用这个函数,看一个人抽到什么碎片,返回抽到的碎片
//func getwhatsuipian(openid string) int {
//	stm := Db.QueryRow("SELECT sui1,sui2,sui3,sui4,sui5,sui6,sui7,sui8,sui9 FROM `drawusers` where openid=?", openid)
//	var jq = make([]int, 9) //碎片量
//	err := stm.Scan(&jq[0], &jq[1], &jq[2], &jq[3], &jq[4], &jq[5], &jq[6], &jq[7], &jq[8])
//	basesui := 1.3    //mmax(jq)
//	var jiaquan = make([]float64, 9) //加权
//	for i, _ := range jiaquan {
//		if basesui - float64(jq[i])<=0{
//			jiaquan[i] = 0
//		}else {
//			jiaquan[i] = basesui - float64(jq[i])
//		}
//
//	}
//
//	var jieguo = util.WeightedRandomIndex(jiaquan)
//	fmt.Println(jieguo)
//	stm2 := fmt.Sprintf("update drawusers set sui%d=sui%d+1 WHERE openid = '%s'", jieguo+1, jieguo+1, openid)
//	_, err = Db.Exec(stm2)
//	fmt.Println(jiaquan)
//	util.Check(err)
//	return jieguo + 1
//}
// 每次抽碎片调用这个函数,看一个人抽到什么碎片,返回抽到的碎片
func getwhatsuipian(openid string) int {
	var stm Drawusers
	if Db.Where("openid = ?",openid).First(&stm).RowsAffected==0{
		fmt.Println("没有这个用户")
		return 0
	}
	//stm := Db.QueryRow("SELECT sui1,sui2,sui3,sui4,sui5,sui6,sui7,sui8,sui9 FROM `drawusers` where openid=?", openid)
	var jq = make([]int, 9) //碎片量
	//这样写也太sb了，一定要看看怎么优化这里，问问别人
	jq[0] = stm.Sui1
	jq[1] = stm.Sui2
	jq[2] = stm.Sui3
	jq[3] = stm.Sui4
	jq[4] = stm.Sui5
	jq[5] = stm.Sui6
	jq[6] = stm.Sui7
	jq[7] = stm.Sui8
	jq[8] = stm.Sui9
	//err := stm.Scan(&jq[0], &jq[1], &jq[2], &jq[3], &jq[4], &jq[5], &jq[6], &jq[7], &jq[8])
	basesui := 1.3    //mmax(jq)
	var jiaquan = make([]float64, 9) //加权
	for i, _ := range jiaquan {
		if basesui - float64(jq[i])<=0{
			jiaquan[i] = 0
		}else {
			jiaquan[i] = basesui - float64(jq[i])
		}

	}

	var jieguo = util.WeightedRandomIndex(jiaquan)
	fmt.Println(jieguo)
	if err:=Db.Model(&stm).Where("openid = ?",openid).Update("sui"+strconv.Itoa(jieguo+1),gorm.Expr(fmt.Sprintf("sui%d+1",jieguo+1))).Error;err!=nil{
		fmt.Println(err)
		return 0
	}
	//fmt.Println(stm)
	//stm2 := fmt.Sprintf("update drawusers set sui%d=sui%d+1 WHERE openid = '%s'", jieguo+1, jieguo+1, openid)
	//_, err = Db.Exec(stm2)
	//fmt.Println(jiaquan)
	//util.Check(err)
	return jieguo + 1
}

//// ChouFra 抽取碎片
//func ChouFra(uid string,times int)([]int,error){
//	sql := fmt.Sprintf("update drawusers set chou = chou-1 where openid = '%s'", uid)
//	_, err := Db.Exec(sql)
//	//check(err)
//	if err!=nil{
//		return nil,err
//	}
//	fmt.Println(sql)
//	if times == 14 {
//		sui1, sui2 := getwhatsuipian(uid), getwhatsuipian(uid)
//		//m := map[string]interface{}{"errcode": 0, "data": map[string]interface{}{
//		//	"fragment": []int{sui1, sui2},
//		//}}
//		//context.JSON(http.StatusOK, m)
//		return []int{sui1,sui2},nil
//
//	} else {
//		sui1 := getwhatsuipian(uid)
//		//m := map[string]interface{}{"errcode": 0, "data": map[string]interface{}{
//		//	"fragment": []int{sui1},
//		//}}
//		//context.JSON(http.StatusOK, m)
//		return []int{sui1},nil
//	}
//}

// ChouFra 抽取碎片
func ChouFra(uid string,times int)([]int,error){
	//sql := fmt.Sprintf("update drawusers set chou = chou-1 where openid = '%s'", uid)
	var user Drawusers
	if err := Db.Model(&user).Where("openid = ?",uid).Update("chou", gorm.Expr("chou-1")).Error;err!=nil{
		return nil,err
	}
	//_, err := Db.Exec(sql)
	//fmt.Println(sql)
	if times == 14 {
		sui1, sui2 := getwhatsuipian(uid), getwhatsuipian(uid)
		//m := map[string]interface{}{"errcode": 0, "data": map[string]interface{}{
		//	"fragment": []int{sui1, sui2},
		//}}
		//context.JSON(http.StatusOK, m)
		return []int{sui1,sui2},nil

	} else {
		sui1 := getwhatsuipian(uid)
		//m := map[string]interface{}{"errcode": 0, "data": map[string]interface{}{
		//	"fragment": []int{sui1},
		//}}
		//context.JSON(http.StatusOK, m)
		return []int{sui1},nil
	}
}

//// PushTheLucky 抽取获奖的用户
//func PushTheLucky() {
//	stm := fmt.Sprintf("delete from luckydogs where thing=0")
//	fmt.Println(stm)
//	res, err := Db.Exec(stm)
//	fmt.Println(res)
//	affect, _ := res.RowsAffected() // affect就是受影响的行数，为0则没有删除成功
//	if affect == 0 {
//		fmt.Println("不允许调用抽奖用户")
//		return
//	}
//	//此语句是在drawusers中抽取所有满足条件的用户，但是现在抽取的用户改为在候选人中抽取，所以此用法废除
//	//stm = fmt.Sprintf("SELECT openid FROM `drawusers` where sui1>=1 and sui2>=1 and sui3>=1 and sui4>=1 and sui5>=1 and sui6>=1 and sui7>=1 and sui8>=1 and sui9>=1")
//	stm = fmt.Sprintf("select SID,nickname,picture from candidatedogs")
//
//
//	rows, err := Db.Query(stm)
//	util.Check(err)
//	var candidates []map[string]interface{}
//	var id,nickname,pic string
//	for rows.Next() {
//		rows.Scan(&id,&nickname,&pic)
//		temp := make(map[string]interface{}, 3)
//		temp["openid"] = id
//		temp["nickname"] = nickname
//		temp["pic"] = pic
//		candidates = append(candidates, temp)
//	}
//	lens := len(candidates)
//	fmt.Println(candidates)
//	rand.Seed(time.Now().Unix())
//	rand.Shuffle(lens, func(i int, j int) {
//		candidates[i], candidates[j] = candidates[j], candidates[i]
//	})
//	if lens >= 8 {
//		stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',1,'%s','%s')", candidates[0]["openid"],candidates[0]["nickname"],candidates[0]["pic"])
//		Db.Exec(stm)
//		for _, candidate := range candidates[1:3] {
//			stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',2,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
//			Db.Exec(stm)
//		}
//		for _, candidate := range candidates[3:8] {
//			stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',3,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
//			Db.Exec(stm)
//		}
//	} else if lens >= 3 {
//		stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',1,'%s','%s')", candidates[0]["openid"],candidates[0]["nickname"],candidates[0]["pic"])
//		Db.Exec(stm)
//		for _, candidate := range candidates[1:3] {
//			stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',2,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
//			Db.Exec(stm)
//		}
//		for _, candidate := range candidates[3:] {
//			stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',3,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
//			Db.Exec(stm)
//		}
//	} else if lens >= 1 {
//		stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',1,'%s','%s')", candidates[0]["openid"],candidates[0]["nickname"],candidates[0]["pic"])
//		Db.Exec(stm)
//		for _, candidate := range candidates[1:] {
//			stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',2,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
//			Db.Exec(stm)
//		}
//	}
//	fmt.Println(candidates)
//}

// PushTheLucky 抽取获奖的用户
func PushTheLucky() {
	var luckydog Luckydogs
	if Db.Where("thing = 0").Delete(&luckydog).RowsAffected == 0{
		fmt.Println("不允许调用抽奖用户")
		return
	}
	//stm := fmt.Sprintf("delete from luckydogs where thing=0")
	//fmt.Println(stm)
	//res, err := Db.Exec(stm)
	//fmt.Println(res)
	//affect, _ := res.RowsAffected() // affect就是受影响的行数，为0则没有删除成功
	//if affect == 0 {
	//	fmt.Println("不允许调用抽奖用户")
	//	return
	//}

	//此语句是在drawusers中抽取所有满足条件的用户，但是现在抽取的用户改为在候选人中抽取，所以此用法废除
	//stm = fmt.Sprintf("SELECT openid FROM `drawusers` where sui1>=1 and sui2>=1 and sui3>=1 and sui4>=1 and sui5>=1 and sui6>=1 and sui7>=1 and sui8>=1 and sui9>=1")
	var candidates []Candidatedogs
	if err := Db.Find(&candidates).Error ; err!=nil{
		fmt.Println("PushTheLucky 有错误")
	}
	fmt.Println(candidates, "\n")
	//stm = fmt.Sprintf("select SID,nickname,picture from candidatedogs")


	//rows, err := Db.Query(stm)
	//util.Check(err)
	//var candidates []map[string]interface{}
	//var id,nickname,pic string
	//for rows.Next() {
	//	rows.Scan(&id,&nickname,&pic)
	//	temp := make(map[string]interface{}, 3)
	//	temp["openid"] = id
	//	temp["nickname"] = nickname
	//	temp["pic"] = pic
	//	candidates = append(candidates, temp)
	//}
	lens := len(candidates)

	//fmt.Println(candidates)
	rand.Seed(time.Now().Unix())
	rand.Shuffle(lens, func(i int, j int) {
		candidates[i], candidates[j] = candidates[j], candidates[i]
	})

	if lens >= 8 {
		luckydog.Nickname,luckydog.Sid,luckydog.Thing,luckydog.Picture = candidates[0].Nickname,candidates[0].Sid,1,candidates[0].Picture
		Db.Create(&luckydog)
		luckydog = Luckydogs{}
		//stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',1,'%s','%s')", candidates[0]["openid"],candidates[0]["nickname"],candidates[0]["pic"])
		//Db.Exec(stm)
		for _, candidate := range candidates[1:3] {
			luckydog.Nickname,luckydog.Sid,luckydog.Thing,luckydog.Picture = candidate.Nickname,candidate.Sid,2,candidate.Picture
			Db.Create(&luckydog)
			luckydog = Luckydogs{}
			//stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',2,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
			//Db.Exec(stm)
		}
		for _, candidate := range candidates[3:8] {
			luckydog.Nickname,luckydog.Sid,luckydog.Thing,luckydog.Picture = candidate.Nickname,candidate.Sid,3,candidate.Picture
			Db.Create(&luckydog)
			luckydog = Luckydogs{}
			//stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',3,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
			//Db.Exec(stm)
		}
	} else if lens >= 3 {
		luckydog.Nickname,luckydog.Sid,luckydog.Thing,luckydog.Picture = candidates[0].Nickname,candidates[0].Sid,1,candidates[0].Picture
		Db.Create(&luckydog)
		luckydog = Luckydogs{}
		//stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',1,'%s','%s')", candidates[0]["openid"],candidates[0]["nickname"],candidates[0]["pic"])
		//Db.Exec(stm)
		for _, candidate := range candidates[1:3] {
			luckydog.Nickname,luckydog.Sid,luckydog.Thing,luckydog.Picture = candidate.Nickname,candidate.Sid,2,candidate.Picture
			Db.Create(&luckydog)
			luckydog = Luckydogs{}
			//stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',2,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
			//Db.Exec(stm)
		}
		for _, candidate := range candidates[3:] {
			luckydog.Nickname,luckydog.Sid,luckydog.Thing,luckydog.Picture = candidate.Nickname,candidate.Sid,3,candidate.Picture
			Db.Create(&luckydog)
			luckydog = Luckydogs{}
			//stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',3,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
			//Db.Exec(stm)
		}
	} else if lens >= 1 {
		luckydog.Nickname,luckydog.Sid,luckydog.Thing,luckydog.Picture = candidates[0].Nickname,candidates[0].Sid,1,candidates[0].Picture
		Db.Create(&luckydog)
		luckydog = Luckydogs{}
		//stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',1,'%s','%s')", candidates[0]["openid"],candidates[0]["nickname"],candidates[0]["pic"])
		//Db.Exec(stm)
		for _, candidate := range candidates[1:] {
			luckydog.Nickname,luckydog.Sid,luckydog.Thing,luckydog.Picture = candidate.Nickname,candidate.Sid,2,candidate.Picture
			Db.Create(&luckydog)
			luckydog = Luckydogs{}
			//stm = fmt.Sprintf("insert into luckydogs (SID,thing,nickname,picture) values ('%s',2,'%s','%s')", candidate["openid"],candidate["nickname"],candidate["pic"])
			//Db.Exec(stm)
		}
	}
	fmt.Println(candidates)
}

//// Getmyfra 查询用户自己的碎片
//func Getmyfra(uid string)([]int,error){
//	sql := fmt.Sprintf("SELECT sui1,sui2,sui3,sui4,sui5,sui6,sui7,sui8,sui9 from drawusers where openid = '%s'", uid)
//	fmt.Println(sql)
//	rows := Db.QueryRow(sql)
//	var fra = make([]int, 9)
//	err := rows.Scan(&fra[0], &fra[1], &fra[2], &fra[3], &fra[4], &fra[5], &fra[6], &fra[7], &fra[8])
//	return fra,err
//}

// Getmyfra 查询用户自己的碎片
func Getmyfra(uid string)([]int,error){
	var user Drawusers
	fmt.Println(user)
	err := Db.Where("openid = ?",uid).First(&user).Error
	var fra = make([]int, 9)
	fmt.Println(user)
	fra[0], fra[1], fra[2], fra[3], fra[4], fra[5], fra[6], fra[7], fra[8] =
		user.Sui1, user.Sui2, user.Sui3, user.Sui4, user.Sui5, user.Sui6, user.Sui7, user.Sui8, user.Sui9
	return fra,err
}

//// Choutimes 查询抽奖次数
//func Choutimes(uid string)(int,error){
//	sql := fmt.Sprintf("SELECT chou FROM `drawusers` where openid = '%s'", uid)
//	fmt.Println(sql)
//	row := Db.QueryRow(sql)
//	var times int
//	err :=row.Scan(&times)
//	return times,err
//}

// Choutimes 查询抽奖次数
func Choutimes(uid string)(int,error){
	var user Drawusers
	err := Db.Select("chou").Where("openid = ?",uid).First(&user).Error
	//sql := fmt.Sprintf("SELECT chou FROM `drawusers` where openid = '%s'", uid)
	//fmt.Println(sql)
	//row := Db.QueryRow(sql)
	var times int
	times = user.Chou
	//err :=row.Scan(&times)
	return times,err
}

//// How 返回中几等奖
//func How(uid string)(int,error){
//	sql := fmt.Sprintf("SELECT thing FROM `luckydogs` where SID = '%s'", uid)
//	fmt.Println(sql)
//	row := Db.QueryRow(sql)
//	var giftt int
//	row.Scan(&giftt)
//	if giftt == 0 {
//		fmt.Println("您没有抽到礼物")
//	} else {
//		fmt.Println("你的礼物是", giftt)
//	}
//	return giftt,nil
//}

// How 返回中几等奖
func How(uid string)(int,error){
	var luckydog Luckydogs
	//sql := fmt.Sprintf("SELECT thing FROM `luckydogs` where SID = '%s'", uid)
	Db.Select("thing").Where("SID = ?",uid).First(&luckydog)
	//fmt.Println(sql)
	//row := Db.QueryRow(sql)
	var giftt int
	giftt = luckydog.Thing
	//row.Scan(&giftt)
	if giftt == 0 {
		fmt.Println("您没有抽到礼物")
	} else {
		fmt.Println("你的礼物是", giftt)
	}
	return giftt,nil
}

// HowPrice 查询123等奖的人
func HowPrice()(interface{},error){
	//var id,pic string                       //获奖用户的信息，可能需要用户的头像，还需要修改
	var firstprice []map[string]string  // 一等奖的信息
	var secondprice []map[string]string // 二等奖的信息
	var thirdprice []map[string]string  // 三等奖的信息
	var luckydogs []Luckydogs
	Db.Select("nickname,picture").Where("thing = 1").Find(&luckydogs)
	//sql := fmt.Sprintf("SELECT nickname,picture FROM `luckydogs` where thing = 1")
	for _, luckydog := range luckydogs{
		temp := make(map[string]string)
		temp["wxNickName"] = luckydog.Nickname
		temp["picture"] = luckydog.Picture
		firstprice = append(firstprice, temp)
	}
	fmt.Println(firstprice)
	luckydogs = []Luckydogs{}

	Db.Select("nickname,picture").Where("thing = 2").Find(&luckydogs)
	//sql := fmt.Sprintf("SELECT nickname,picture FROM `luckydogs` where thing = 1")
	for _, luckydog := range luckydogs{
		temp := make(map[string]string)
		temp["wxNickName"] = luckydog.Nickname
		temp["picture"] = luckydog.Picture
		secondprice = append(secondprice, temp)
	}
	fmt.Println(secondprice)
	luckydogs = []Luckydogs{}

	Db.Select("nickname,picture").Where("thing = 3").Find(&luckydogs)
	//sql := fmt.Sprintf("SELECT nickname,picture FROM `luckydogs` where thing = 1")
	for _, luckydog := range luckydogs{
		temp := make(map[string]string)
		temp["wxNickName"] = luckydog.Nickname
		temp["picture"] = luckydog.Picture
		thirdprice = append(thirdprice, temp)
	}
	fmt.Println(thirdprice)
	luckydogs = []Luckydogs{}
	//rows, _ := Db.Query(sql)
	//for rows.Next() {
	//	rows.Scan(&id,&pic)
	//	temp := make(map[string]string)
	//	temp["wxNickName"] = id
	//	temp["picture"] = pic
	//	firstprice = append(firstprice, temp)
	//}


	//sql = fmt.Sprintf("SELECT nickname,picture FROM `luckydogs` where thing = 2")
	//rows, _ = Db.Query(sql)
	//for rows.Next() {
	//	rows.Scan(&id,&pic)
	//	temp := make(map[string]string)
	//	temp["wxNickName"] = id
	//	temp["picture"] = pic
	//	secondprice = append(secondprice, temp)
	//}
	//fmt.Println(secondprice)
	//
	//sql = fmt.Sprintf("SELECT nickname,picture FROM `luckydogs` where thing = 3")
	//rows, _ = Db.Query(sql)
	//for rows.Next() {
	//	rows.Scan(&id,&pic)
	//	temp := make(map[string]string)
	//	temp["wxNickName"] = id
	//	temp["picture"] = pic
	//	thirdprice = append(thirdprice, temp)
	//}
	fmt.Println(thirdprice)
	m := map[string]interface{}{
		"level1": firstprice,
		"level2": secondprice,
		"level3": thirdprice,
	}
	return m,nil
}
//
//// 查询123等奖的人
//func HowPrice()(interface{},error){
//	var id,pic string                       //获奖用户的信息，可能需要用户的头像，还需要修改
//	var firstprice []map[string]string  // 一等奖的信息
//	var secondprice []map[string]string // 二等奖的信息
//	var thirdprice []map[string]string  // 三等奖的信息
//
//	sql := fmt.Sprintf("SELECT nickname,picture FROM `luckydogs` where thing = 1")
//	rows, _ := Db.Query(sql)
//	for rows.Next() {
//		rows.Scan(&id,&pic)
//		temp := make(map[string]string)
//		temp["wxNickName"] = id
//		temp["picture"] = pic
//		firstprice = append(firstprice, temp)
//	}
//	fmt.Println(firstprice)
//
//	sql = fmt.Sprintf("SELECT nickname,picture FROM `luckydogs` where thing = 2")
//	rows, _ = Db.Query(sql)
//	for rows.Next() {
//		rows.Scan(&id,&pic)
//		temp := make(map[string]string)
//		temp["wxNickName"] = id
//		temp["picture"] = pic
//		secondprice = append(secondprice, temp)
//	}
//	fmt.Println(secondprice)
//
//	sql = fmt.Sprintf("SELECT nickname,picture FROM `luckydogs` where thing = 3")
//	rows, _ = Db.Query(sql)
//	for rows.Next() {
//		rows.Scan(&id,&pic)
//		temp := make(map[string]string)
//		temp["wxNickName"] = id
//		temp["picture"] = pic
//		thirdprice = append(thirdprice, temp)
//	}
//	fmt.Println(thirdprice)
//	m := map[string]interface{}{
//				"level1": firstprice,
//				"level2": secondprice,
//				"level3": thirdprice,
//	}
//	return m,nil
//}